package com.capinfo.accounting.web;

import java.util.Date;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.NativeWebRequest;

import com.capinfo.accumulation.model.accounting.mybist.ZDPZCWPZMB;
import com.capinfo.accumulation.model.accounting.mybist.ZDPZFZZPZMB;
import com.capinfo.accumulation.model.accounting.mybist.ZDPZMBJBSJ;
import com.capinfo.accumulation.model.pagemodel.Json;
import com.capinfo.accumulation.parameter.accounting.DataGrid;
import com.capinfo.accumulation.service.accounting.mybits.ZDPZCWPZMBServiceI;
import com.capinfo.accumulation.service.accounting.mybits.ZDPZFZZPZMBServiceI;
import com.capinfo.accumulation.service.accounting.mybits.ZDPZMBJBSJServiceI;
import com.capinfo.commons.project.model.security.SystemUser;
import com.capinfo.components.security.web.utils.WebRequestUtils;



/**
 *  @author zxl
 */
@Controller
@RequestMapping("/business/accounting/zdpzmb")

public class ZDPZMBJBSJController extends BaseController {
	@Autowired
	public ZDPZMBJBSJServiceI zDPZMBJBSJService;
	@Autowired
	public ZDPZCWPZMBServiceI  zDPZCWPZMBService;
	@Autowired
	public ZDPZFZZPZMBServiceI  zDPZFZZPZMBService;

	@RequestMapping("/dataGrid.shtml")
	@ResponseBody
	public DataGrid dataGrid(@RequestParam  Map param) {
		return zDPZMBJBSJService.findbyByGrid(param);
	}
	
	@RequestMapping("/add.shtml")
	@ResponseBody
	public Json add(ZDPZMBJBSJ t , HttpSession session,NativeWebRequest request) {
		Json j = new Json();
		SystemUser user = (SystemUser)WebRequestUtils.retrieveSecureUser(request);
		try {
			
			zDPZMBJBSJService.insert(t);
			j.setSuccess(true);
			j.setMsg("新增成功");
			j.setObj(t);
		} catch (Exception e) {
			 e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/edit.shtml")
	@ResponseBody
	public Json edit(ZDPZMBJBSJ t , HttpSession session) {
		Json j = new Json();
		try {
			zDPZMBJBSJService.updateByPrimaryKeySelective(t);
			j.setSuccess(true);
			j.setMsg("编辑成功");
			j.setObj(t);
		} catch (Exception e) {
			 e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/delete")
	@ResponseBody
	public Json delete(String id) {
		Json j = new Json();
		try {
			zDPZMBJBSJService.deleteByPrimaryKey(id);
			j.setSuccess(true);
			j.setMsg("删除成功");
		} catch (Exception e) {
			 e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/selectByid")
	@ResponseBody
	public ZDPZMBJBSJ selectByid(String id) {
		return zDPZMBJBSJService.selectByPrimaryKey(id);
	}
	
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/manager.shtml")
	public String manager() {
		return "business/accounting/zdpzmb/search";
	}
	
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/addPage.shtml")
	public String addPage(HttpServletRequest request) {
		ZDPZMBJBSJ zDPZMBJBSJ  = new ZDPZMBJBSJ();
		request.setAttribute("zDPZMBJBSJ", zDPZMBJBSJ);
	return "/business/accounting/zdpzmb/zDPZMBJBSJAdd";
	}
	
	
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/editPage.shtml")
	public String editPage(HttpServletRequest request,String id) {
		
		request.setAttribute("id",id);
		return "/business/accounting/zdpzmb/zDPZMBJBSJEdit";
	}
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/viewPage")
	public String viewPage(String id ,HttpServletRequest request) {
		ZDPZMBJBSJ zDPZMBJBSJ = this.zDPZMBJBSJService.selectByPrimaryKey(id);
		request.setAttribute("zDPZMBJBSJ", zDPZMBJBSJ);
		return "/zDPZMBJBSJ/zDPZMBJBSJView";
	}
}
